﻿//-----------------------------------------------------------------------
// <copyright file="LogSystem.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.Log
{
    using System;

    /// <summary>
    /// Static class which holds the global log manager instance.
    /// 
    /// If the log manager instance has not been set and it is accessed,
    /// an exception will be thrown.
    /// </summary>
    public class LogSystem
    {
        #region Fields - Private

        /// <summary>
        /// Job manager instance.
        /// </summary>
        private static ILogManager manager = null;

        #endregion

        #region Properties - Public

        /// <summary>
        /// Gets or sets the log manager instance.
        /// </summary>
        public static ILogManager Manager
        {
            get
            {
                if (manager == null)
                {
                    throw new InvalidOperationException("Log manager instance must be set before the class can be used.");
                }

                return manager;
            }

            set
            {
                manager = value;
            }
        }

        #endregion

        #region Methods - Public

        /// <summary>
        /// Add the passed target to the set of targets log messages
        /// are output to.
        /// </summary>
        /// <param name="target">Target to add to the manager.</param>
        public static void AddOutputTarget(ILogOutputTarget target)
        {
            Manager.AddOutputTarget(target);
        }

        /// <summary>
        /// Remove the passed target from the set of output targets.
        /// </summary>
        /// <param name="target">Target to remove from the manager.</param>
        public static void RemoveOutputTarget(ILogOutputTarget target)
        {
            Manager.RemoveOutputTarget(target);
        }

        /// <summary>
        /// Log a formatted string to the passed log level.
        /// </summary>
        /// <param name="level">Log level for the message.</param>
        /// <param name="group">Group this log message is associated with.</param>
        /// <param name="format">Message format.</param>
        /// <param name="args">Message args.</param>
        public static void Log(LogLevel level, string group, string format, params object[] args)
        {
            Manager.Log(level, group, format, args);
        }

        /// <summary>
        /// Log a formatted string to the info log level.
        /// </summary>
        /// <param name="group">Group this log message is associated with.</param>
        /// <param name="format">Message format.</param>
        /// <param name="args">Message args.</param>
        public static void LogInfo(string group, string format, params object[] args)
        {
            Log(LogLevel.Info, group, format, args);
        }

        /// <summary>
        /// Log a formatted string to the error log level.
        /// </summary>
        /// <param name="group">Group this log message is associated with.</param>
        /// <param name="format">Message format.</param>
        /// <param name="args">Message args.</param>
        public static void LogError(string group, string format, params object[] args)
        {
            Log(LogLevel.Error, group, format, args);
        }

        /// <summary>
        /// Log a formatted string to the startup log level.
        /// </summary>
        /// <param name="group">Group this log message is associated with.</param>
        /// <param name="format">Message format.</param>
        /// <param name="args">Message args.</param>
        public static void LogStartup(string group, string format, params object[] args)
        {
            Log(LogLevel.Startup, group, format, args);
        }

        #endregion
    }
}
